﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Alerts_Administration_2010.interfaces.views;
using Alerts_Administration_2010.interfaces.models;

namespace Alerts_Administration_2010.classes.controller
{
    public class OverviewController
    {
        #region private fields
        private SPWeb _site;
        private IOverviewView _view;
        #endregion

        #region public properties
        public IOverviewView AttachedView
        {
            get
            {
                return _view;
            }
            set
            {
                _view = value;

                foreach (SPAlert a in _site.Alerts)
                {
                    IOverviewItem item = AttachedView.CreateOverviewItem(a.ID.ToString());
                    item.AlertName = a.Title;
                    item.AlertType = a.AlertType.ToString();
                    item.EventType = a.EventType.ToString();
                    item.List = a.List.Title;
                    item.UserName = a.User.Name;
                    AttachedView.AddOverviewItem(item);
                }

                //_view.EditClicked += new EventHandler<EventArgs>(_view_EditClicked);
                _view.Render();
            }
        }
        #endregion

        public OverviewController(SPWeb site)
        {
            _site = site;
        }
    }
}
